]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
popupMenu: Expose SwitchItem state as GObject property
authorFlorian Müllner <fmuellner@gnome.org>
Mon, 16 Dec 2024 13:21:18 +0000 (14:21 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Fri, 10 Jan 2025 11:46:47 +0000 (12:46 +0100)
This will allow using bindings instead of explicit signal connections.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3576>
(cherry picked from commit 296e5c32e4470b7026c4e08affeeaec9eb80aa52)

js/ui/popupMenu.js

index efc7e464f2f8c2aea859f1bae4bdba5015a159e4..72e2b278ade4fde89b624b2686b680d3492e64c4 100644 (file)
@@ -531,6 +531,12 @@ export const Switch = GObject.registerClass({
 });
 
 export const PopupSwitchMenuItem = GObject.registerClass({
+    Properties: {
+        'state': GObject.ParamSpec.boolean(
+            'state', null, null,
+            GObject.ParamFlags.READWRITE,
+            false),
+    },
     Signals: {'toggled': {param_types: [GObject.TYPE_BOOLEAN]}},
 }, class PopupSwitchMenuItem extends PopupBaseMenuItem {
     _init(text, active, params) {
@@ -602,12 +608,20 @@ export const PopupSwitchMenuItem = GObject.registerClass({
         return this._switch.state;
     }
 
+    set state(state) {
+        if (this._switch.state === state)
+            return;
+
+        this._switch.set({state});
+    }
+
     setToggleState(state) {
-        this._switch.state = state;
+        this.set({state});
     }
 
     _onToggled() {
         this.emit('toggled', this._switch.state);
+        this.notify('state');
         this._checkAccessibleState();
     }